<style lang="less">
</style>

<template>
<div>
 <Card>  
        <p slot="title">
            <Icon type="navicon-round"></Icon>
            简内容管理
        </p>       
    <Button-group>
        <Button @click="addjxinxi(0)">添加</Button>
        <Button @click="delduo">批量删除</Button>
    </Button-group>
    <div style="margin-top:10px"></div>
    <i-table :columns="cols" :data="data" stripe @on-selection-change="setselect" @on-sort-change="setorder" ></i-table>
    
    <div style="margin-top:10px; text-align:center">
    <Page :total="pageinfo.total" :page-size="pageinfo.pagesize" show-sizer @on-change="pagechange" @on-page-size-change="pagesizechange"></Page></div>
    </Card>
    </div>
</template>

<script>
import api from '../../libs/api';
export default {
    name: 'content_jxinxi',
    data () {
        return {  
            cols:[{
                    type: 'selection',
                    width: 40,
                    align: 'center'
                },{
                    title: 'ID',
                    key: 'ID',
                    width:70,
                    sortable:'custom'
                }, {
                    title: '标题',
                    key: 'title',
                    align:'left',
                    sortable:'custom',
                    render:(h,params)=>{
                        return h('Button',
                                    {
                                        props: {
                                            type: 'text',//无边框，像文字格式
                                            size: 'small',
                                        },
                                        on:  {
                                                click: () => {        
                                                    this.addjxinxi(params.row.ID); 
                                                }
                                        }
                                    },
                                    params.row.title)
                    }
                }, {
                    title: '英文标题',
                    key: 'etitle',
                    align:'left',
                    sortable:'custom'
                },{
                    title: '标识',
                    key: 'flag',
                    align:'left',
                    sortable:'custom'
                },
                {
                    title: '操作',
                    key: 'action',
                    align: 'center',
                        width:'120px',
                    render: (h, params) => {
                        return h('div',
                            [
                                h('Button',
                                    {
                                        props: {
                                            //type: 'text',//无边框，像文字格式
                                            size: 'small',
                                        },
                                        on:  {
                                                click: () => {        
                                                    this.addjxinxi(params.row.ID); 
                                                }
                                        }
                                    },
                                    '编辑'),
                                    h('span',' '),
                                h('Button',
                                    {
                                        props: {
                                            //type: 'text',//无边框，像文字格式
                                            size: 'small',
                                        },
                                        on: {
                                            click: () => {
                                                this.deljxinxi(params.index);
                                            }
                                        }
                                    },
                                    '删除')
                            ])
                    }
                }],
            data:[],
            pageinfo:{page:1,pagesize:20,total:0,order:"ID",esc:"desc",key:''},
            editData:{},
            fdata:[],
            selectdata:[],
            modaltitle:"添加"
        };
    },
    methods:{
        pagesizechange(pagesize){
            this.pageinfo.pagesize=pagesize;
            this.init();
        },
        pagechange(page){
            this.pageinfo.page=page;
            this.init();
        },
        setorder(column){
            if(column.order=="normal"){
            this.pageinfo.order="ID";
            this.pageinfo.esc="desc";
            }
            else{
            this.pageinfo.order=column.key;
            this.pageinfo.esc=column.order;
            }
            this.init();
        },
        deljxinxi(index){
            var vm=this;            
            api.post("/jxinxi/del?id="+vm.data[index].ID).then(function(res){
                if(res.data.code==200){
                    vm.$Message.success(res.data.msg);
                }
                else{
                    vm.$Message.error(res.data.msg);
                }
                vm.init();
            })
        },
        setselect(selection){
            this.selectdata=selection;
        },
        delduo(){
            var vm=this; 
            api.post("/jxinxi/delall",{data:this.selectdata}).then(function(res){
                if(res.data.code==200){
                    vm.$Message.success("删除成功！");
                }
                vm.init();
            })
        },
        addjxinxi(id){                                                    
            let query = {ID:id};
            this.$router.push({
                name: 'content_jxinxiadd',
                query: query
            });
        },
        init(){
            var vm=this;
            api.post("/jxinxi/getpagelist?t="+new Date().getSeconds(),this.pageinfo).then(function(res){
                var linkslist=res.data.msg.Items;                
                vm.data=linkslist;
                vm.pageinfo.total=res.data.msg.TotalItems;
            })
        }
    },
    created(){
        this.init();
    }
};
</script>
